<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>欢迎登录</title>
    <link rel="stylesheet" type="text/css" href="/tp3.2/Public/css/login.css">
    <script type="text/javascript" src="/tp3.2/Public/js/jquery-3.2.0.min.js"></script>
</head>
<body>
<div class="header">
    <div class="header-login"><a href="<?php echo U('Index/index');?>">BackStage</a></div>
    <div class="header-nav">
        <a class="header-url" href="">添加文章</a>
        <a class="header-url" href="">客户资料</a>
        <a class="header-url" href="">账号设置</a>
    </div>
</div>
<div class="main">
    <div class="main-form">
        <p style="text-align: center">login</p>
            <label class="form-input">
                <span class="form-tag" style="margin-right:70px">mail:</span>
                <input type="text" id="username" placeholder="请输入电子邮箱">
                <span class="tip"><a href="<?php echo U('User/register');?>">注册账号</a></span>
            </label>
            <label class="form-input"><span class="warn1"></span></label>
            <label class="form-input">
                <span class="form-tag">password:</span>
                <input type="password" id="password" placeholder="请输入密码">
                <span class="tip"><a href="" id="fpass">忘记密码</a></span>
            </label>
            <label class="form-input"><span class="warn2"></span></label>
            <label class="form-input">
                <span class="form-tag"></span>
                <input type="button" id="button" value="立即登录">
            </label>
    </div>
</div>
<div class="footer"></div>
</body>
<script type="text/javascript">
    $("#fpass").on('click',function(){
        window.alert('请联系管理员！')
    })
    $("#button").on('click',function(){
        var mail=$("#username").val();
        var password=$("#password").val();
        var l1=mail.length;
        var l2=password.length;
        if (l1== 0) {
            $(".warn1").css("color", "#FF0512");
            $(".warn1").text("✘请输入电子邮箱！");
        } else {
            $("#username").attr("index", "1");
            var i=$("#username").attr("index");/*定义输入框状态属性*/
        }
        if (l2==0) {
            $(".warn2").css("color", "#FF0512");
            $(".warn2").text("✘请输入密码！");
        } else {
            $("#password").attr("index", "1");
            var j=$("#password").attr("index");/*定义输入框状态属性*/
        }

        /*若输入状态正常则发送数据到服务器验证*/
        if(i==1&&j==1){
            $.ajax({
                type: "POST",
                url: "<?php echo U('Home/Ajax/login');?>",
                data: {mail: mail ,password: password},
                dataType: "text",
                success:function(re){
                    if(re==1){
                        window.location.href="<?php echo U('Home/User/listarticle');?>"
                    }else if(re==0){
                        window.alert("邮箱或密码错误！");
                        $("#password").val('');
                    }else if(re==2){
                        window.alert("访问受限");
                        window.location.reload();
                    }
                }
            })
        }
    })
</script>
</html>